<?php
final class Loader
{
	public function __get($key)
	{
		return Registry::get($key);
	}
	
	public function __set($key, $value)
	{
		Registry::set($key,$value);
	}
	
	public function hasClass($str)
	{		
		$strs = explode('/', $str);				
		
		foreach ($strs as $part){
			if(!isset($key)){
				$key = $part;
			}
			else {
				$key = $key . "_" . $part;
			}
		}			
		
		//$key = $strs[0] . '_' . strtolower($strs[1]);
		return Registry::has($key);
	}
	
	public function __construct()
	{
		
	}
	
	public function model($model) {
		$strs = explode('/', $model);
				
		$count = count($strs); 		
		
		// get keyword			
		foreach ($strs as $part){
			if(!isset($key)){
				$key = $part;
			}
			else {
				$key = $key . "_" . $part;
			}
		}
				
		// file name<br>
		$file  = DIR_MODEL;
		for($i = 1; $i < $count - 1; $i ++) {
			$file = $file . strtolower($strs[$i]) ."/";		    
		}
		$file = $file . strtolower($strs[$count -1]) . '.php';		
			
		// class name
		$class = "";
		foreach ($strs as $str)
		{
			$class = $class . $str ;
		}							
		
		if (file_exists($file)) 
		{			
			include_once($file);			
			$instance = new $class();			
			
			/*if($instance == null || !isset($instance))
			{
				echo "DEBUG_model/new class null ** ";
			} else {
				$instance->test();
			}*/
					
			Registry::set($key, $instance);			
		} 
		else 
		{
			exit('Error: Could not load model ' . $model . '!');			
		}
	}
}
?>